with open(r"d:\a.txt","w",encoding="utf-8") as f:
    f.write("这是测试文件")


with open("d:\\a.txt","a",encoding="utf-8") as f:
    f.write("这是测试文件")

with open("d:/a.txt","a",encoding="utf-8") as f:
    f.write("这是测试文件")

